import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/// 使用Pageview.builder来创建
///
///  在使用pageview.builder时候，需要注意的点是，必须设置itemCount这个属性，否则会有问题
///
void main() {
  runApp(MaterialApp(
    home: PageviewBuilderuse(),
  ));
}

class PageviewBuilderuse extends StatefulWidget {
  const PageviewBuilderuse({super.key});

  @override
  State<PageviewBuilderuse> createState() => _PageviewBuilderuseState();
}

class _PageviewBuilderuseState extends State<PageviewBuilderuse> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('pageviewbuilder'),
      ),
      body: PageView.builder(
          scrollDirection: Axis.vertical, // 默认是水平方向滚动的
          itemCount: 10,
          itemBuilder: (context, index) {
            return Mypage23(count: index);
          }),
    );
  }
}

class Mypage23 extends StatefulWidget {
  final int count;
  const Mypage23({super.key, required this.count});

  @override
  State<Mypage23> createState() => _Mypage23State();
}

class _Mypage23State extends State<Mypage23> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text(
        '这是第 ${widget.count} 页',
        style: Theme.of(context).textTheme.headlineMedium,
      ),
    );
  }
}
